// AUTHOR : PRIYESH ANAND
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pp pop_back
#define dsort(a,n) sort(a,a+n,greater<int>())
#define min_heap priority_queue<int, vector<int>, greater<int>> pq;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
/* BE A BOSS */
using namespace std;
void dfs(int i, vector<int> adj[], vector<int>& DFS) {
DFS.pb(i);
int cnt=0;
for(auto it:adj[i]) {
dfs(it,adj,DFS);
}
}
int cntsize(int i, vector<int> adj[], vector<int>& cnt) {
cnt[i]=adj[i].size();
for(auto it:adj[i]) {
cnt[i]+=cntsize(it,adj,cnt);
}
return cnt[i];
}
void wrong_answer() {
int n,q,a;
cin>>n>>q;
vector<int> adj[n+1];
for(int i=2; i<=n; ++i) {
cin>>a;
adj[a].pb(i);
}
vector<int> DFS;
dfs(1,adj,DFS);
vector<int> cnt(n+1,0);
cntsize(1,adj,cnt);
for(int i=1; i<=n; ++i) {
cnt[i]+=1;
}
map<int,int> mp;
for(int i=0; i<n; ++i) {
mp[DFS[i]]=i;
}
int u,k;
while(q--) {
cin>>u>>k;
int x=mp[u];
int y=x+(k-1);
if(y-x+1>cnt[u] or y>=n)cout<<-1<<endl;
else cout<<DFS[y]<<endl;
}
}
int main ()
{
fast;
// int t;
// cin>>t;
// while(t--)
wrong_answer();
return 0;
}
// --------------------------------Binary Exponentiation-----------------------------------//
// ll binpow(ll a, ll b) {
// ll res = 1;
// while (b > 0) {
// if (b & 1)
// res = res * a;
// a = a * a;
// b >>= 1;
// }
// return res;
// }
//-------------------------------Seive of Erathonesthenes-----------------------------------//
// void SieveOfEratosthenes(ll n)
// {
// bool prime[n + 1];
// memset(prime, true, sizeof(prime));
// for (ll p = 2; p * p <= n; p++)
// {
// if (prime[p] == true)
// {
// for (ll i = p * p; i <= n; i += p)
// prime[i] = false;
// //v.push_back(i);
// }
// }
// }
//-----------------------------SPF(Smallest Prime Factor) array------------------------------//
// ll spf[n];
// for(int i=0;i<=n;i++){
// spf[i] = i;
// }
// for(int i=2;i*i<=n;i++){
// if(spf[i]==i){
// for(int j=i*i;j<=n;j+=i){
// if(spf[j]==j){
// spf[j]=i;
// }
// }
// }
// }
//--------------------------------------NO. of digit---------------------------------------//
// ll ndig(ll n){
// ll tmp= n,ctr=0;
// while(tmp>0){
// tmp/=10;
// ctr++;
// }
// return ctr;
// // take care: if n==0 this fn returns 0.
// }
//------------------------------------------------------------------------------------------//
//sort(a,a+n,greater<ll>()); //---> to sort in descending order.
//
// Custom Comparator:
//
// bool cmpr(pair<ll,ll> a,pair<ll,ll> b){
// return(a.second<b.second);
//}
//sort(v.begin(),v.end(),cmpr);
//#define min_heap priority_queue<int, vector<int>, greater<int>> pq;
1589C - Two Arrays | 1510K - King's Task |
126B - Password | 462A - Appleman and Easy Task |
839C - Journey | 622A - Infinite Sequence |
659C - Tanya and Toys | 1266A - Competitive Programmer |
234C - Weather | 1332C - K-Complete Word |
525C - Ilya and Sticks | 1555C - Coin Rows |
1324C - Frog Jumps | 715A - Plus and Square Root |
774D - Lie or Truth | 1186D - Vus the Cossack and Numbers |
505B - Mr Kitayuta's Colorful Graph | 1324D - Pair of Topics |
157B - Trace | 34C - Page Numbers |
279A - Point on Spiral | 1294D - MEX maximizing |
447A - DZY Loves Hash | 23B - Party |
63D - Dividing Island | 1203E - Boxers |
1547F - Array Stabilization (GCD version) | 358A - Dima and Continuous Line |
1385C - Make It Good | 651A - Joysticks |